import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-08-28
 * Time: 20:50
 * To BE A Better Person-2020-3-2
 */
public class TestDemo2 {
    public static int countCharacters(String[] words, String chars) {
        HashMap<Character,Integer> charsMap=new HashMap<>();
        int num=0;
        int j=0;
        //将每个字母放入另一个哈希表
        for(int i=0;i<chars.length();i++){
            int val=charsMap.getOrDefault(chars.charAt(i),0);
            val++;
            charsMap.put(chars.charAt(i),val);
        }

        //将单词对应回字母表里
        for(int i=0;i<words.length;i++){
            for(j=0;j<words[i].length();j++){
                Integer val1=charsMap.get(words[i].charAt(j));
                if(val1==null){
                    break;
                    //hhh
                }
                int val= val1;
                val--;
                charsMap.put(words[i].charAt(j),val);
            }
            if(j==words[i].length()){
                num++;
            }
        }

        return num;
    }
    public static void main(String[] args) {
        //["cat","bt","hat","tree"]
        //"atach"
        String[] words={"dyiclysmffuhibgfvapygkorkqllqlvokosagyelotobicwcmebnpznjbirzrzsrtzjxhsfpiwyfhzyonmuabtlwin","ndqeyhhcquplmznwslewjzuyfgklssvkqxmqjpwhrshycmvrb","ulrrbpspyudncdlbkxkrqpivfftrggemkpyjl","boygirdlggnh","xmqohbyqwagkjzpyawsydmdaattthmuvjbzwpyopyafphx","nulvimegcsiwvhwuiyednoxpugfeimnnyeoczuzxgxbqjvegcxeqnjbwnbvowastqhojepisusvsidhqmszbrnynkyop","hiefuovybkpgzygprmndrkyspoiyapdwkxebgsmodhzpx","juldqdzeskpffaoqcyyxiqqowsalqumddcufhouhrskozhlmobiwzxnhdkidr","lnnvsdcrvzfmrvurucrzlfyigcycffpiuoo","oxgaskztzroxuntiwlfyufddl","tfspedteabxatkaypitjfkhkkigdwdkctqbczcugripkgcyfezpuklfqfcsccboarbfbjfrkxp","qnagrpfzlyrouolqquytwnwnsqnmuzphne","eeilfdaookieawrrbvtnqfzcricvhpiv","sisvsjzyrbdsjcwwygdnxcjhzhsxhpceqz","yhouqhjevqxtecomahbwoptzlkyvjexhzcbccusbjjdgcfzlkoqwiwue","hwxxighzvceaplsycajkhynkhzkwkouszwaiuzqcleyflqrxgjsvlegvupzqijbornbfwpefhxekgpuvgiyeudhncv","cpwcjwgbcquirnsazumgjjcltitmeyfaudbnbqhflvecjsupjmgwfbjo","teyygdmmyadppuopvqdodaczob","qaeowuwqsqffvibrtxnjnzvzuuonrkwpysyxvkijemmpdmtnqxwekbpfzs","qqxpxpmemkldghbmbyxpkwgkaykaerhmwwjonrhcsubchs"};
        String chars="usdruypficfbpfbivlrhutcgvyjenlxzeovdyjtgvvfdjzcmikjraspdfp";
        int num=countCharacters(words,chars);
        System.out.println(num);
    }
}
